package otherTest;

import java.text.AttributedCharacterIterator;
import java.text.DateFormatSymbols;
import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

@SuppressWarnings("serial")
public class SafeSimpleDateFormat extends SimpleDateFormat
{
    private final ThreadLocal<SimpleDateFormat> mvThreadLocalSDF;

    public SafeSimpleDateFormat()
    {
        super();
        mvThreadLocalSDF = new ThreadLocal<SimpleDateFormat>()
        {
            protected SimpleDateFormat initialValue()
            {
                return new SimpleDateFormat();
            }
        };
    }

    public SafeSimpleDateFormat(final String pattern)
    {
        super(pattern);
        mvThreadLocalSDF = new ThreadLocal<SimpleDateFormat>()
        {
            protected SimpleDateFormat initialValue()
            {
                return new SimpleDateFormat(pattern);
            }
        };
    }

    public SafeSimpleDateFormat(final String pattern, final DateFormatSymbols formatSymbols)
    {
        super(pattern, formatSymbols);
        mvThreadLocalSDF = new ThreadLocal<SimpleDateFormat>()
        {
            protected SimpleDateFormat initialValue()
            {
                return new SimpleDateFormat(pattern, formatSymbols);
            }
        };
    }

    public SafeSimpleDateFormat(final String pattern, final Locale locale)
    {
        super(pattern, locale);
        mvThreadLocalSDF = new ThreadLocal<SimpleDateFormat>()
        {
            protected SimpleDateFormat initialValue()
            {
                return new SimpleDateFormat(pattern, locale);
            }
        };
    }

    public Object parseObject(String source) throws ParseException
    {
        return mvThreadLocalSDF.get().parseObject(source);
    }

    public String toString()
    {
        return mvThreadLocalSDF.get().toString();
    }

    public Date parse(String source) throws ParseException
    {
        return mvThreadLocalSDF.get().parse(source);
    }

    public Object parseObject(String source, ParsePosition pos)
    {
        return mvThreadLocalSDF.get().parseObject(source, pos);
    }

    public void setCalendar(Calendar newCalendar)
    {
        mvThreadLocalSDF.get().setCalendar(newCalendar);
    }

    public Calendar getCalendar()
    {
        return mvThreadLocalSDF.get().getCalendar();
    }

    public void setNumberFormat(NumberFormat newNumberFormat)
    {
        mvThreadLocalSDF.get().setNumberFormat(newNumberFormat);
    }

    public NumberFormat getNumberFormat()
    {
        return mvThreadLocalSDF.get().getNumberFormat();
    }

    public void setTimeZone(TimeZone zone)
    {
        mvThreadLocalSDF.get().setTimeZone(zone);
    }

    public TimeZone getTimeZone()
    {
        return mvThreadLocalSDF.get().getTimeZone();
    }

    public void setLenient(boolean lenient)
    {
        mvThreadLocalSDF.get().setLenient(lenient);
    }

    public boolean isLenient()
    {
        return mvThreadLocalSDF.get().isLenient();
    }

    public void set2DigitYearStart(Date startDate)
    {
        mvThreadLocalSDF.get().set2DigitYearStart(startDate);
    }

    public Date get2DigitYearStart()
    {
        return mvThreadLocalSDF.get().get2DigitYearStart();
    }

    public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos)
    {
        return mvThreadLocalSDF.get().format(date, toAppendTo, pos);
    }

    public AttributedCharacterIterator formatToCharacterIterator(Object obj)
    {
        return mvThreadLocalSDF.get().formatToCharacterIterator(obj);
    }

    public Date parse(String text, ParsePosition pos)
    {
        return mvThreadLocalSDF.get().parse(text, pos);
    }

    public String toPattern()
    {
        return mvThreadLocalSDF.get().toPattern();
    }

    public String toLocalizedPattern()
    {
        return mvThreadLocalSDF.get().toLocalizedPattern();
    }

    public void applyPattern(String pattern)
    {
        mvThreadLocalSDF.get().applyPattern(pattern);
    }

    public void applyLocalizedPattern(String pattern)
    {
        mvThreadLocalSDF.get().applyLocalizedPattern(pattern);
    }

    public DateFormatSymbols getDateFormatSymbols()
    {
        return mvThreadLocalSDF.get().getDateFormatSymbols();
    }

    public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols)
    {
        mvThreadLocalSDF.get().setDateFormatSymbols(newFormatSymbols);
    }

    public Object clone()
    {
        return mvThreadLocalSDF.get().clone();
    }

    public int hashCode()
    {
        return mvThreadLocalSDF.get().hashCode();
    }

    public boolean equals(Object obj)
    {
        return mvThreadLocalSDF.get().equals(obj);
    }
}